home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / internet-tools / amitcp / amitcp-sdk-4.3 / doc / netlib.doc < prev    next >
Encoding:
Text File  |  1996-02-04  |  59.4 KB  |  1,815 lines

  1. TABLE OF CONTENTS
  2.  
  3. net.lib/autoinit
  4. net.lib/autoinit_timer.device
  5. net.lib/autoinit_usergroup.library
  6. net.lib/charRead
  7. net.lib/chmod
  8. net.lib/chown
  9. net.lib/dup
  10. net.lib/dup2
  11. net.lib/fstat
  12. net.lib/gettimeofday
  13. net.lib/herror
  14. net.lib/init_inet_daemon
  15. net.lib/lineRead
  16. net.lib/lstat
  17. net.lib/perror
  18. net.lib/popen
  19. net.lib/PrintNetFault
  20. net.lib/PrintUserFault
  21. net.lib/rcmd
  22. net.lib/serveraccept
  23. net.lib/set_socket_stdio
  24. net.lib/sleep
  25. net.lib/SPrintf
  26. net.lib/stat
  27. net.lib/strerror
  28. net.lib/syslog
  29. net.lib/usleep
  30. net.lib/utime
  31. netd.lib/dosio_init
  32. net.lib/autoinit                                             net.lib/autoinit
  33.  
  34.    NAME
  35.        autoinit - SAS C Autoinitialization Functions
  36.  
  37.    SYNOPSIS
  38.        LONG _STI_200_openSockets(void)
  39.  
  40.        void _STD_200_closeSockets(void)
  41.  
  42.    FUNCTION
  43.        These functions open and close the bsdsocket.library at the startup
  44.        and exit of the program, respectively.  For a program to use these
  45.        functions, it must be linked with netlib:net.lib (or some variant).
  46.        These functions are linked in only if the program references the
  47.        global symbol "SocketBase".
  48.  
  49.        If the library can be opened, the _STI_200_openSockets() calls
  50.        bsdsocket.library function SocketBaseTags() to tell the library the
  51.        address and the size of the errno variable of the calling program,
  52.        the program name (to be used in syslog() messages) and the address
  53.        of the h_error variable (in which the name resolver errors are
  54.        returned).
  55.  
  56.    NOTES
  57.        _STI_200_openSockets() also checks that the system version is at
  58.        least 37. It also puts up a requester if the bsdsocket.library is
  59.        not found or is of wrong version.
  60.  
  61.        The autoinitialization and autotermination functions are features
  62.        specific to the SAS C6.  However, these functions can be used with
  63.        other (ANSI) C compilers, too. Example follows:
  64.  
  65.        /* at start of main() */
  66.  
  67.        atexit(_STD_200_closeSockets);
  68.        if (_STI_200_openSockets() != 0)
  69.           exit(20);
  70.  
  71.    BUGS
  72.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  73.        6.50 or latter.  Only way to terminate an initialization function is
  74.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  75.        function is terminated by exit() call with SAS C 6.50 binary, the
  76.        autotermination functions won't be called.  Due this braindamage
  77.        these compilers require separate net.lib libraries.
  78.  
  79.    SEE ALSO
  80.        bsdsocket.library/SocketBaseTags(),
  81.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  82.        autotermination functions.
  83.  
  84. net.lib/autoinit_timer.device                   net.lib/autoinit_timer.device
  85.  
  86.    NAME
  87.        timerinit - SAS C Autoinitialization Functions for timer.device
  88.  
  89.    SYNOPSIS
  90.        #include <time.h>
  91.    
  92.        int daylight;
  93.        long timezone;
  94.        char *tzname[2];
  95.  
  96.        void tzset(void);
  97.  
  98.        #include <sys/time.h>
  99.  
  100.        struct Device *TimerBase;
  101.  
  102.        LONG _STI_200_openTimer(void);
  103.        void _STD_200_closeTimer(void);
  104.        
  105.    FUNCTION
  106.        These functions open and close the timer.device at the startup and
  107.        exit of the program, respectively. For a program to use these
  108.        functions, it must be linked with netlib:net.lib.
  109.  
  110.        The opened device base is stored in the TimerBase global variable.
  111.  
  112.        If the device can be opened, the _STIopenTimer() sets up the time zone
  113.        information, which is used by the gettimeofday() function and the time
  114.        conversion routines of the C-library.
  115.  
  116.    NOTES
  117.        The time zone information is got from the environment variable named
  118.        TZ. The format for this variable is:
  119.  
  120.            zzznnnddd
  121.  
  122.        where zzz is three letter identifier for the time zone (for example
  123.        GMT), and the nnn is hours west from Greenwich on range [-23,24]
  124.        (negative values are to east).  The last field is the abbreviation for
  125.        the local daylight saving time zone (which is not interpreted by this
  126.        version).
  127.  
  128.        If the TZ environment variable cannot be found, Greenwich Mean Time
  129.        (GMT) is used instead.
  130.  
  131.        The autoinitialization and autotermination functions are features
  132.        specific to the SAS C6.  However, these functions can be used with
  133.        other (ANSI) C compilers, too.  Example follows:
  134.  
  135.        /* at start of main() */
  136.  
  137.        atexit(_STD_200_closeTimer);
  138.        _STI_200_openTimer();
  139.  
  140.        The tzset() does nothing. All the necessary initialization is done at
  141.        the autoinit function.
  142.  
  143.    BUGS
  144.        TZ "hours west from GMT" should be interpreted as float.
  145.  
  146.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  147.        6.50 or latter.  Only way to terminate an initialization function is
  148.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  149.        function is terminated by exit() call with SAS C 6.50 binary, the
  150.        autotermination functions won't be called.  Due this braindamage
  151.        these compilers require separate net.lib libraries.
  152.  
  153.    SEE ALSO
  154.        net.lib/gettimeofday(),
  155.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  156.        autotermination functions.
  157. net.lib/autoinit_usergroup.library         net.lib/autoinit_usergroup.library
  158.  
  159.    NAME
  160.        autoinit usergroup.library - SAS C Autoinitialization Functions
  161.  
  162.    SYNOPSIS
  163.        error = _STI_200_openUserGroup()
  164.  
  165.        LONG _STI_200_openUserGroup(void)
  166.  
  167.        _STD_200_closeUserGroup()
  168.  
  169.        void _STD_200_closeUserGroup(void)
  170.  
  171.    FUNCTION
  172.        These functions open and close the usergroup.library at the startup
  173.        and exit of the program, respectively.  For a program to use these
  174.        functions, it must be linked with netlib:usr.lib.
  175.  
  176.    NOTES
  177.        _STI_200_openUserGroup() also checks that the system version is at
  178.        least 37.  It puts up a requester if the usergroup.library is not
  179.        found or is too old version.
  180.  
  181.        The autoinitialization and autotermination functions are features
  182.        specific to the SAS C6.  However, these functions can be used with
  183.        other (ANSI) C compilers, too.  Example follows:
  184.  
  185.        /* at start of main() */
  186.  
  187.        atexit(_STD_200_closeUserGroup);
  188.        if (_STI_200_openUserGroup() != 0)
  189.           exit(20);
  190.  
  191.    BUGS 
  192.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  193.        6.50 or latter.  Only way to terminate an initialization function is
  194.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  195.        function is terminated by exit() call with SAS C 6.50 binary, the
  196.        autotermination functions won't be called.  Due this braindamage
  197.        these compilers require separate net.lib libraries.
  198.  
  199.    SEE ALSO
  200.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  201.        autotermination functions.
  202.  
  203. net.lib/charRead                                             net.lib/charRead
  204.  
  205.    NAME
  206.        charRead -- read characters from socket one by one.
  207.  
  208.    SYNOPSIS
  209.        initCharRead(rc, fd)
  210.  
  211.        void initCharRead(struct CharRead *, int);
  212.  
  213.  
  214.        character = charRead(rc)
  215.  
  216.        int charRead(struct CharRead *);
  217.  
  218.  
  219.    DESCRIPTION
  220.        charRead is a macro package which return characters one by one 
  221.        from given socket input stream. The socket where data is to be read
  222.        is set by calling initCharRead(): rc is the pointer to charread
  223.        structure previously allocated. fd is the (socket) descriptor where
  224.        reading is to be done.
  225.  
  226.        charRead() returns the next character from input stream or one of
  227.        the following:
  228.  
  229.        RC_DO_SELECT    (-3)    - read input buffer is returned. Do select
  230.                                  before next call if you don't want charread
  231.                                  to block.
  232.  
  233.        RC_EOF          (-2)    - end-of-file condition has occurred.
  234.  
  235.        RC_ERROR        (-1)    - there has been an error while filling new
  236.                                  charread buffer. Check the value of Errno()
  237.  
  238.    NOTE
  239.        Always use variable of type int to store return value from charRead()
  240.        since the numeric value of characters returned may vary between
  241.        0 -255 (or even greater). As you may know, -3 equals 253 if of type
  242.        unsigned char.
  243.  
  244.    EXAMPLE
  245.        /*
  246.         * This piece of code shows how to use charread with select()
  247.         */
  248.        #include <sys/types.h>
  249.        #include <sys/socket.h>
  250.        #include <charread.h>
  251.  
  252.        main_loop(int sock)
  253.        {
  254.          struct CharRead rc;
  255.          fd_set readfds;
  256.          int c;
  257.  
  258.          initCharRead(&rc, sock);
  259.  
  260.          FD_ZERO(&readfds);
  261.  
  262.          while(1) {
  263.            FD_SET(sock, &readfds);     
  264.  
  265.            if (select(sock + 1. &readfds, NULL, NULL, NULL)) < 0) {
  266.              perror("select");
  267.              break;
  268.            }
  269.            if (FD_ISSET(sock, &readfds)) {
  270.              while((c = charRead(&rc)) >= 0)
  271.                handle_next_input_character(c);
  272.              if (c == RC_EOF)
  273.                break;
  274.              if (c == RC_ERROR) {
  275.                perror("charRead");
  276.                break;
  277.              }
  278.            }
  279.          }
  280.        }
  281.  
  282.     PORTABILITY
  283.        The source file charread.h should be able to be used in 
  284.        UNIX programs as is.
  285.  
  286.     SEE ALSO
  287.        lineRead(), bsdsocket.library/recv()
  288. net.lib/chmod                                                   net.lib/chmod
  289.  
  290.    NAME
  291.        chmod, fchmod - change mode of file
  292.  
  293.    SYNOPSIS
  294.        #include <sys/stat.h>
  295.  
  296.        int chmod(const char *path, mode_t mode);
  297.  
  298.        int fchmod(int fd, mode_t mode);
  299.  
  300.    DESCRIPTION
  301.        The function chmod() sets the file permission bits of the file
  302.        specified by the pathname path to mode. Fchmod() sets the permission
  303.        bits of the specified file descriptor fd. Chmod() verifies that the
  304.        process owner (user) either owns the file specified by path (or fd),
  305.        or is the super-user.  A mode is created from or'd permission bit
  306.        masks defined in <sys/stat.h>:
  307.  
  308.              #define S_IRWXU 0000700    /* RWX mask for owner */
  309.              #define S_IRUSR 0000400    /* R for owner */
  310.              #define S_IWUSR 0000200    /* W for owner */
  311.              #define S_IXUSR 0000100    /* X for owner */
  312.  
  313.              #define S_IRWXG 0000070    /* RWX mask for group */
  314.              #define S_IRGRP 0000040    /* R for group */
  315.              #define S_IWGRP 0000020    /* W for group */
  316.              #define S_IXGRP 0000010    /* X for group */
  317.  
  318.              #define S_IRWXO 0000007    /* RWX mask for other */
  319.              #define S_IROTH 0000004    /* R for other */
  320.              #define S_IWOTH 0000002    /* W for other */
  321.              #define S_IXOTH 0000001    /* X for other */
  322.  
  323.              #define S_ISUID 0004000    /* set user id on execution */
  324.              #define S_ISGID 0002000    /* set group id on execution */
  325.              #define S_ISVTX 0001000    /* save swapped text even after use *
  326. /
  327.  
  328.        The ISVTX (the sticky bit) indicates to the system which executable
  329.        files are shareable (pure).
  330.  
  331.        Writing or changing the owner of a file turns off the set-user-id
  332.        and set-group-id bits unless the user is the super-user.  This makes
  333.        the system somewhat more secure by protecting set-user-id
  334.        (set-group-id) files from remaining set-user-id (set-group-id) if
  335.        they are modified.
  336.  
  337.    RETURN VALUES
  338.        Upon successful completion, a value of 0 is returned.  Otherwise, a
  339.        value of -1 is returned and errno is set to indicate the error.
  340.  
  341.    ERRORS
  342.        Chmod() will fail and the file mode will be unchanged if:
  343.  
  344.        [ENOTDIR]     A component of the path prefix is not a directory.
  345.  
  346.        [ENAMETOOLONG]
  347.                      A component of a pathname exceeded 255 characters, or
  348.                      an entire path name exceeded 1023 characters.
  349.  
  350.        [ENOENT]      The named file does not exist.
  351.  
  352.        [EACCES]      Search permission is denied for a component of the
  353.                      path prefix.
  354.  
  355.        [EPERM]       The effective user ID does not match the owner of the
  356.                      file and the effective user ID is not the super-user.
  357.  
  358.        [EROFS]       The named file resides on a read-only file system.
  359.  
  360.        [EFAULT]      Path points outside the process's allocated address
  361.                      space.
  362.  
  363.        [EIO]         An I/O error occurred while reading from or writing to
  364.                      the file system.
  365.  
  366.        Fchmod() will fail if:
  367.  
  368.        [EBADF]       The descriptor is not valid.
  369.  
  370.        [EINVAL]      Fd refers to a socket, not to a file.
  371.  
  372.        [EROFS]       The file resides on a read-only file system.
  373.  
  374.        [EIO]         An I/O error occurred while reading from or writing to
  375.                      the file system.
  376.  
  377.    NOTES
  378.        This call is provided for Unix compatibility.  It does not know all
  379.        Amiga protection bits (Delete, Archive, Script).  The archive and
  380.        script bits are cleared, Delete set according the Write bit.
  381.  
  382.    SEE ALSO
  383.        open(),  chown(),  stat()
  384.  
  385. net.lib/chown                                                   net.lib/chown
  386.  
  387.    NAME
  388.        chown - change owner and group of a file
  389.  
  390.    SYNOPSIS
  391.        #include <unistd.h>
  392.  
  393.        success = chown(path, owner, group)
  394.  
  395.        int chown(const char *, uid_t, gid_t);
  396.  
  397.    DESCRIPTION
  398.        The owner ID and group ID of the file named by path or referenced by
  399.        fd is changed as specified by the arguments owner and group.  The
  400.        owner of a file may change the group to a group of which he or she is
  401.        a member, but the change owner capability is restricted to the
  402.        super-user.
  403.  
  404.        Chown() clears the set-user-id and set-group-id bits on the file to
  405.        prevent accidental or mischievious creation of set-user-id and
  406.        set-group-id programs.
  407.  
  408.        One of the owner or group id's may be left unchanged by specifying it
  409.        as -1.
  410.  
  411.        If the final component of path is a symbolic link, the ownership and
  412.        group of the symbolic link is changed, not the ownership and group of
  413.        the file or directory to which it points.
  414.  
  415.    RETURN VALUES
  416.        Zero is returned if the operation was successful; -1 is returned if an
  417.        error occurs, with a more specific error code being placed in the
  418.        global variable errno.
  419.  
  420.    ERRORS
  421.        Chown() will fail and the file will be unchanged if:
  422.  
  423.        [ENOTDIR]     A component of the path prefix is not a directory.
  424.  
  425.        [EINVAL]      The pathname contains a character with the high-order
  426.                      bit set.
  427.  
  428.        [ENAMETOOLONG]
  429.                      A component of a pathname exceeded 80 characters, or an
  430.                      entire path name exceeded 1023 characters.
  431.  
  432.        [ENOENT]      The named file does not exist.
  433.  
  434.        [EACCES]      Search permission is denied for a component of the path
  435.                      prefix.
  436.  
  437.        [ELOOP]       Too many symbolic links were encountered in translating
  438.                      the pathname.
  439.  
  440.        [EPERM]       The effective user ID is not the super-user.
  441.  
  442.        [EROFS]       The named file resides on a read-only file system.
  443.  
  444.        [EFAULT]      Path points outside the process's allocated address
  445.                      space.
  446.  
  447.        [EIO]         An I/O error occurred while reading from or writing to
  448.                      the file system.
  449.  
  450.    SEE ALSO
  451.        chmod(2)
  452.  
  453. net.lib/dup                                                       net.lib/dup
  454.  
  455.    NAME
  456.        dup, dup2 - duplicate an existing file descriptor
  457.  
  458.    SYNOPSIS
  459.        #include <unistd.h>
  460.  
  461.        int dup(int oldd)
  462.  
  463.        int dup2(int oldd, int newd)
  464.  
  465.    FUNCTION
  466.        Dup() duplicates an existing object descriptor and returns its value
  467.        to the calling program (newd = dup(oldd)). The argument oldd is a
  468.        small nonnegative integer index in the program's descriptor table.
  469.        The value must be less than the size of the table, which is returned
  470.        by getdtablesize().  The new descriptor returned by the call is the
  471.        lowest numbered descriptor currently not in use by the program.
  472.  
  473.        The object referenced by the descriptor does not distinguish between
  474.        oldd and newd in any way.  Thus if newd and oldd are duplicate
  475.        references to an open file, read() and write() calls all move a single
  476.        pointer into the file, and append mode, non-blocking I/O and
  477.        asynchronous I/O options are shared between the references.  If a
  478.        separate pointer into the file is desired, a different object
  479.        reference to the file must be obtained by issuing an additional open()
  480.        call.  The close-on-exec flag on the new file descriptor is unset.
  481.  
  482.        In dup2(), the value of the new descriptor newd is specified.  If this
  483.        descriptor is already in use, the descriptor is first deallocated as
  484.        if a close() call had been done first.
  485.  
  486.    RETURN VALUES
  487.        The value -1 is returned if an error occurs in either call.  The
  488.        external variable errno indicates the cause of the error.
  489.  
  490.    BUGS
  491.        The current UFB implementation for SAS C allows only sockets to be
  492.        duplicated.
  493.  
  494.    ERRORS
  495.        Dup() and dup2() fail if:
  496.  
  497.        [EBADF]       Oldd or newd is not a valid active descriptor
  498.  
  499.        [EMFILE]      Too many descriptors are active.
  500.  
  501.    SEE ALSO
  502.        accept(),  open(),  close(),  socket(),  getdtablesize()
  503.  
  504.    STANDARDS
  505.        Dup() and dup2() are expected to conform to IEEE Std 1003.1-1988
  506.        (``POSIX'').
  507.  
  508.    COPYRIGHT
  509.        This manual page is copyright © 1980, 1991 Regents of the
  510.        University of California.  All rights reserved.
  511.  
  512. net.lib/dup2                                                     net.lib/dup2
  513.    SEE ALSO
  514.        dup()
  515. net.lib/fstat                                                   net.lib/fstat
  516.  
  517.    SEE ALSO
  518.        stat()
  519.  
  520. net.lib/gettimeofday                                     net.lib/gettimeofday
  521.  
  522.    NAME   
  523.        gettimeofday - get date and time 
  524.  
  525.    SYNOPSIS
  526.        #include <sys/time.h>
  527.  
  528.        error = gettimeofday(tp, tzp)
  529.  
  530.        int gettimeofday(struct timeval *, struct timezone *)
  531.  
  532.    FUNCTION
  533.        The system's notion of the current Greenwich time and the
  534.        current time zone is obtained with the gettimeofday() call.
  535.        The time is expressed in seconds and microseconds since
  536.        midnight (0 hour), January 1, 1970.  The resolution of the
  537.        system clock is hardware dependent. If tzp is zero, the time
  538.        zone information will not be returned. Also, if your system
  539.        software is unable to provide time zone information, the
  540.        structure pointed by tzp will be filled with zeroes.
  541.   
  542.    PORTABILITY
  543.        UNIX
  544.  
  545.    INPUTS
  546.        The structures pointed to by tp and tzp are defined in
  547.        <sys/time.h> as:
  548.   
  549.             struct timeval {
  550.                  long tv_sec;      /* seconds since Jan. 1, 1970 */
  551.                  long tv_usec;     /* and microseconds */
  552.             };
  553.   
  554.             struct timezone {
  555.                  int  tz_minuteswest;   /* of Greenwich */
  556.                  int  tz_dsttime;  /* type of dst correction to apply */
  557.             };
  558.   
  559.        The timezone structure indicates the local time zone (meas-
  560.        ured in minutes of time westward from Greenwich), and a flag
  561.        that, if nonzero, indicates that Daylight Saving time
  562.        applies locally during the appropriate part of the year.
  563.  
  564.    RESULT
  565.        Returns 0 when successful and -1 with specific error code in 
  566.        errno in case of an error. No error codes are specified,
  567.        however.
  568.        
  569.    NOTES
  570.        gettimeofday() uses GetSysTime() function of the timer.device,
  571.        which is new to V36 of the device.
  572.  
  573.        Time zone information is taken from the locale.library, if it
  574.        is available (it is included in all Amiga systems from 2.1 and
  575.        up). Otherwise the environment variable "TZ" is consulted. If
  576.        it fails, the time zone is initialized to the GMT.
  577.  
  578.        Global variable TimerBase _must_ be initialized before
  579.        gettimeofday() is called. This is normally done automatically
  580.        by the autoinit module (timerinit.c) included in the net.lib.
  581.  
  582.    SEE ALSO
  583.        timer.device/GetSysTime()
  584. net.lib/herror                                                 net.lib/herror
  585.  
  586.    NAME
  587.        herror - print name resolver error message to stderr.
  588.  
  589.    SYNOPSIS
  590.        #include <clib/netlib_protos.h>
  591.  
  592.        herror(banner)
  593.        void herror(const char *)
  594.  
  595.    FUNCTION
  596.        The herror() function finds the error message corresponding to the
  597.        current value of host error using the SocketBaseTags() and writes
  598.        it, followed by a newline, to the stderr. If the argument string
  599.        is non-NULL it is used as a prefix to the message string and
  600.        separated from it by a colon and space (`: '). If the argument is
  601.        NULL only the error message string is printed.
  602.  
  603.    NOTES
  604.        The herror() function requires the stdio functions to be linked.
  605.  
  606.    SEE ALSO
  607.        <netinclude:netdb.h>, SocketBaseTagList(), perror()
  608.  
  609. net.lib/init_inet_daemon                             net.lib/init_inet_daemon
  610.  
  611.    NAME
  612.        init_inet_daemon - obtain socket accepted by the inetd
  613.  
  614.    SYNOPSIS
  615.        int init_inet_daemon(void);
  616.  
  617.    FUNCTION
  618.        Obtain the server socket accepted by the inetd, the Internet
  619.        super-server.
  620.  
  621.    RETURN VALUES
  622.        socket descriptor if successful, -1 with specific error code
  623.        on errno otherwise.
  624.  
  625.    ERRORS
  626.        ENXIO     - The process was not started by the inetd.
  627.  
  628.    NOTES
  629.        If the process was started by the inetd, but the ObtainSocket()
  630.        call fails, then this function exit()s with some specific exit
  631.        code, so that inetd can clean up the unobtained socket.
  632.  
  633.        Use the net.lib function set_socket_stdio() to redirect stdio,
  634.        stdout and stderr to the returned socket, if necessary.
  635.  
  636.    SEE ALSO
  637.        serveraccept(), set_socket_stdio(), bsdsocket/ObtainSocket(),
  638.        netutil/inetd
  639. net.lib/lineRead                                             net.lib/lineRead
  640.  
  641.    NAME
  642.        lineRead -- read newline terminated strings from socket
  643.  
  644.    SYNOPSIS
  645.        initLineRead(rl, fd, lftype, bufsize)
  646.  
  647.        void initLineRead(struct LineRead *, int, int, int);
  648.  
  649.  
  650.        length = lineRead(rl)
  651.  
  652.        int lineread(struct LineRead *);
  653.  
  654.  
  655.    FUNCTION
  656.        lineRead() reads newline terminated strings from given descriptor
  657.        very efficiently. All the options needed are set by calling
  658.        initLineRead(): rl is the pointer to lineread structure previously
  659.        allocated. fd is the (socket) descriptor where reading is to be
  660.        done. lftype can have following 3 values:
  661.  
  662.            RL_LFNOTREQ - Newline terminated strings are returned unless
  663.                          there is no newlines left in currently buffered
  664.                          input. In this case remaining buffer is returned.
  665.  
  666.            RL_LFREQLF  - If there is no newlines left in currently buffered
  667.                          input the remaining input data is copied at the
  668.                          start of buffer. Caller is informed that next
  669.                          call will fill the buffer (and it may block).
  670.                          Lines are always returned with newline at the end
  671.                          unless the string is longer than whole buffer.
  672.  
  673.            RL_LFREQNUL  - Like LF_REQLF, but remaining newline is removed.
  674.                          Note here that lenght is one longer that actual
  675.                          string length since line that has only one
  676.                          newline at the end would return length as 0
  677.                          which indigate string incomplete condition.
  678.  
  679.        bufsize is used to tell lineread how big the receive buffer is.
  680.        always put RL_BUFSIZE here since that value is used to determine
  681.        the memory allocated for the buffer. This option is given to you
  682.        so you may decide to use different buffer size than the default
  683.        1024.
  684.  
  685.        lineRead() returns the newline terminated string in rl_line field
  686.        of lineread structure. Return values of lineRead() are:
  687.  
  688.             1 - RL_BUFSIZE     - normal length of returned string.
  689.  
  690.             0                  - If zero is returned just after select(),
  691.                                  end-of-file condition has occurred.
  692.                                  Otherwise string is not completed yet.
  693.                                  Make sure you call select() (or use non-
  694.                                  blocking IO) if you don't want next call
  695.                                  to block.
  696.  
  697.            -1                  - if rl_Line field of lineread structure
  698.                                  is NULL, it indicates error condition.
  699.                                  If rl_Line points to start of string
  700.                                  buffer, input string has been longer
  701.                                  than buffer. In this case rl_Line points
  702.                                  to zero terminated string of length
  703.                                  RL_BUFSIZE.
  704.  
  705.        You may modify the zero terminated string returned by lineRead() in
  706.        any way, but memory around the string is private lineread memory.
  707.  
  708.    EXAMPLE
  709.        /*
  710.         * The following code shows how to use lineread with select()
  711.         */
  712.        #ifdef USE_LOW_MEMORY_BUFFER
  713.        #define RL_BUFSIZE 256
  714.        #endif
  715.  
  716.        #include <sys/types.h>
  717.        #ifdef AMIGA
  718.        #include <bsdsocket.h>
  719.        #endif
  720.        #include <lineread.h>
  721.  
  722.        #define NULL 0
  723.  
  724.        ...
  725.  
  726.        main_loop(int sock)
  727.        {
  728.          struct LineRead * rl;
  729.          int length;
  730.          fd_set reafdfs;
  731.  
  732.          if (rl = (struct LineRead *)AllocMem(sizeof (*rl), 0)) {
  733.  
  734.            initLineRead(rl, sock, LF_REQLF, RL_BUFSIZE);
  735.  
  736.            FD_ZERO(&readfds);
  737.  
  738.            while(1) {
  739.              FD_SET(sock, &readfds);
  740.  
  741.              if (select(sock + 1, &readfds, NULL, NULL, NULL)) < 0) {
  742.                perror("select");
  743.                break;
  744.              }
  745.              if (FD_ISSET(sock, &readfds))
  746.                if ((length = lineRead(rl)) == 0) /* EOF */
  747.                  break;
  748.                do {
  749.                  if (length > 0)
  750.                    write(1, rl->rl_Line, length); /* stdout. write() for */
  751.                                                   /* speed demonstration */
  752.                  else { /* length == -1 */
  753.                    if (rl->rl_Line == NULL); {
  754.                      perror("lineRead");
  755.                      break;
  756.                    }
  757.                    else {
  758.                      fprintf(stderr, "lineread input buffer overflow!\n");
  759.                      write(1, rl->rl_Line, RL_BUFSIZE);
  760.                      write(1, "\n", 1);
  761.                    }
  762.                  }
  763.                } while ((length = lineRead(rl)) != 0); /* 0 -> do select() */
  764.            }
  765.          FreeMem(rl, sizeof (*rl);
  766.          }
  767.          else
  768.            fprintf("AllocMem: Out Of memory\n");
  769.        }
  770.  
  771.     PORTABILITY
  772.        The source modules lineread.c and lineread.h should compile
  773.        in UNIX machines as is.
  774.  
  775.     SEE ALSO
  776.        charRead(), bsdsocket.library/recv()
  777.  
  778. net.lib/lstat                                                   net.lib/lstat
  779.  
  780.    SEE ALSO
  781.        stat()
  782.  
  783. net.lib/perror                                                 net.lib/perror
  784.  
  785.    NAME
  786.        perror - socket error messages
  787.  
  788.    SYNOPSIS
  789.        extern int errno;
  790.  
  791.        #include <stdio.h>
  792.  
  793.        perror(banner)
  794.        void perror(const char *)
  795.  
  796.    FUNCTION
  797.        The perror() function finds the error message corresponding to the
  798.        current value of the global variable errno and writes it, followed
  799.        by a newline, to the stderr. If the argument string is non-NULL it
  800.        is preappended to the message string and separated from it by a
  801.        colon and space (`: '). If string is NULL only the error message
  802.        string is printed.
  803.  
  804.    NOTES
  805.        The perror() function requires the stdio functions to be linked.
  806.  
  807.    SEE ALSO
  808.        strerror(), PrintNetFault(), <netinclude:sys/errno.h>
  809.  
  810. net.lib/popen                                                   net.lib/popen
  811.    NAME
  812.        popen, pclose - initiate I/O to/from a process
  813.  
  814.    SYNOPSIS
  815.        #include <stdio.h>
  816.  
  817.        FILE *popen(command, type)
  818.        char *command, *type;
  819.  
  820.        pclose(stream)
  821.        FILE *stream;
  822.  
  823.    DESCRIPTION
  824.        The arguments to popen are pointers to null-terminated
  825.        strings containing respectively a command line and an
  826.        I/O mode, either "r" for reading or "w" for writing.  It
  827.        creates a pipe between the calling process and the command
  828.        to be executed.  The value returned is a stream pointer that
  829.        can be used (as appropriate) to write to the standard input
  830.        of the command or read from its standard output.
  831.  
  832.        A stream opened by popen **MUST** be closed by pclose, which
  833.        waits for the associated process to terminate and returns
  834.        the exit status of the command.
  835.  
  836.        Because stdio files are shared, a type "r" command may be
  837.        used as an input filter, and a type "w" as an output filter.
  838.  
  839.    DIAGNOSTICS
  840.        Popen returns a null pointer if files or processes cannot be
  841.        created.
  842.  
  843.        Pclose returns -1 if stream is not associated with a
  844.        `popened' command.
  845.  
  846.    AUTHOR
  847.        Original version by Rick Schaeffer <ricks@isc-br.isc-br.com>
  848. /
  849.  
  850. include <stdio.h>
  851. include <stdlib.h>
  852. include <string.h>
  853. include <stdarg.h>
  854.  
  855. include <exec/types.h>
  856. include <exec/memory.h>
  857. include <dos/dos.h>
  858. include <dos/dosextens.h>
  859. include <dos/record.h>
  860. include <dos/dostags.h>
  861.  
  862. include <proto/exec.h>
  863. include <proto/dos.h>
  864. include <clib/alib_protos.h>
  865.  
  866. include <errno.h>
  867.  
  868. define NOTDEF
  869.  
  870. xtern char *mktemp(char *);
  871.  
  872. truct POmsg {
  873.    struct Message  POm;
  874.    int     rc;
  875.    char        *cmd;
  876.    struct Library  *DOSBase;
  877.    };
  878.  
  879.  
  880. truct pstruct {
  881.    FILE    *fptr;
  882.    struct POmsg    childmsg;
  883.    };
  884.  
  885. define MAXPIPES    6
  886. tatic struct pstruct poarray[MAXPIPES] = { 0 };
  887.  
  888. tatic int childprocess(void);
  889.  
  890. ILE *popen(const char *cmd, const char *mode)
  891.  
  892.    static char tempname[] = "pipe:pXXX.XXX";
  893.    char        *pname,redir[20];
  894.    short       i;
  895.    int         pmode;
  896.    struct pstruct  *poptr;
  897.    struct Process  *child;
  898.    struct CommandLineInterface *cli;
  899.    ULONG stacksize;
  900.    struct Process *thistask;
  901.    FILE            *fptr;
  902.  
  903.    /* First, get pointers to our process and cli structs */
  904.    thistask = (struct Process *) FindTask(NULL);
  905.    cli = Cli();
  906.    poptr = NULL;
  907.  
  908.    /* now find an open pipe (we currently only allow 6 simultaneously
  909.       open pipes) */
  910.    for (i=0; i<MAXPIPES; i++) {
  911.        if (poarray[i].fptr == NULL) {
  912.            poptr = &poarray[i];
  913.            break;
  914.            }
  915.        }
  916.    if (poptr == NULL) {
  917.        fprintf(stderr,"popen: Unable to find an open pipe\n");
  918.        errno = EMFILE;
  919.        return(NULL);
  920.        }
  921.    if (strcmp(mode,"r") == 0)
  922.        pmode = MODE_NEWFILE;
  923.    else if (strcmp(mode,"w") == 0)
  924.        pmode = MODE_OLDFILE;
  925.    else {
  926.        fprintf(stderr,"popen: Mode must be 'r' or 'w'\n");
  927.        errno = EINVAL;
  928.        return(NULL);
  929.        }
  930.  
  931.    /* Try to make a guaranteed unique file name for the pipe */
  932.    strcpy(redir,tempname);
  933.    redir[5] = 'a' + i;
  934.  
  935.    pname = mktemp(redir);            /* set up a pipe: file name */
  936.  
  937.    /* Now get the child's stack and priority set up */
  938.    if (cli)
  939.        stacksize = cli->cli_DefaultStack << 2;
  940.    else
  941.        stacksize = thistask->pr_StackSize;
  942.  
  943.    /* Now open our side of the pipe */
  944.    fptr = fopen(pname,mode);
  945.    if (fptr == NULL) {
  946.        fprintf(stderr,"popen: Unable to open pipe file %s\n",pname);
  947.        return(NULL);
  948.        }
  949.  
  950.    /* create the command.  since the "System" function runs through
  951.       the default shell, we need to tell it not to fail so that we
  952.       ALWAYS get back the exit status.  This wouldn't be necessary
  953.       if the CLI created by the System function inherited the parent's
  954.       FAILAT level.
  955.       The pipe file is passed as redirection to shell, which the 
  956.       SystemTags() will parse. For some reason the default "more"
  957.       could not get it's input properly if redirection was not used.
  958.    */
  959.    poptr->childmsg.cmd = malloc(strlen(cmd) + 15 + 20);
  960.    sprintf(poptr->childmsg.cmd, "failat 9999\n%s %c%s\n",
  961.            cmd, (pmode == MODE_NEWFILE) ? '>' : '<', pname);
  962.  
  963.    /* Create a port that we can get the child's exit status through */
  964.    poptr->childmsg.POm.mn_ReplyPort = CreateMsgPort();
  965.    poptr->childmsg.POm.mn_Node.ln_Type = NT_MESSAGE;
  966.    poptr->childmsg.POm.mn_Node.ln_Pri = 0;
  967.    if (poptr->childmsg.POm.mn_ReplyPort == 0) {
  968.        fclose(fptr);
  969.        fprintf(stderr,"popen: Couldn't create message port\n");
  970.        errno = ENOMEM;
  971.        return(NULL);
  972.        }
  973.  
  974.    /* Now we can start the new process.  NOTE: this is actually going
  975.       to create a process consisting ONLY of the function "childprocess"
  976.       which can be seen below.  childprocess() then runs the command
  977.       passed in the startup message.
  978.    */
  979.    child = CreateNewProcTags(
  980.        NP_Entry,   (Tag) childprocess,
  981.        NP_Input,   Input(),
  982.        NP_Output,  Output(),
  983.        NP_CloseInput,  FALSE,
  984.        NP_CloseOutput, FALSE,
  985.        NP_StackSize,   stacksize,
  986.        NP_Cli,     TRUE,
  987.        TAG_DONE
  988.        );
  989.  
  990.    poptr->childmsg.DOSBase = (struct Library *)DOSBase;
  991.  
  992.    /* now pass the child the startup message */
  993.    PutMsg(&child->pr_MsgPort,(struct Message *) &poptr->childmsg);
  994.  
  995.    return(poptr->fptr = fptr);
  996.  
  997.  
  998. ILE *popenl(const char *arg0, ...)
  999.  
  1000.    va_list ap;
  1001.    char argbuf[512], *mode;
  1002.  
  1003.    strcpy(argbuf, arg0);
  1004.    va_start(ap, arg0);
  1005.    while(1)
  1006.    {
  1007.        char *s = va_arg(ap, char *);
  1008.  
  1009.        if(s == NULL)
  1010.        {
  1011.        strcat(argbuf, "\n");
  1012.        break;
  1013.        } /* if */
  1014.  
  1015.        strcat(argbuf, " ");
  1016.  
  1017.        if(strchr(s, ' '))
  1018.        {
  1019.        strcat(argbuf, "\"");
  1020.        strcat(argbuf, s);
  1021.        strcat(argbuf, "\"");
  1022.        }
  1023.        else
  1024.        {
  1025.        strcat(argbuf, s);
  1026.        } /* if */
  1027.    }
  1028.    mode = va_arg(ap, char *);
  1029.    va_end(ap);
  1030.  
  1031.    return(popen(argbuf, mode));
  1032.  
  1033.  /* popenl */
  1034.  
  1035. nt pclose(FILE *fptr)
  1036.  
  1037.    short       i;
  1038.  
  1039.    /* Figure out which pipe we used for this file */
  1040.    for (i=0; i<MAXPIPES; i++)
  1041.        if (poarray[i].fptr == fptr)
  1042.            break;
  1043.    if (i >= MAXPIPES) {
  1044.        fprintf(stderr,"popen: DISASTER...couldn't find file pointer in pclose
  1045. \n");
  1046.        exit(1);
  1047.        }
  1048.  
  1049.    /* close the file */
  1050.    fclose(fptr);
  1051.  
  1052.    /* now wait for the exit status */
  1053.    WaitPort(poarray[i].childmsg.POm.mn_ReplyPort);
  1054.    poarray[i].fptr = NULL;
  1055.  
  1056.    /* clean things up */
  1057.    DeletePort(poarray[i].childmsg.POm.mn_ReplyPort);
  1058.    free(poarray[i].childmsg.cmd);
  1059.    return(poarray[i].childmsg.rc);
  1060.  
  1061.  
  1062. * SAS/C autoinitialization for cleanup! */
  1063. oid __stdargs _STD_4000_popen(void)
  1064.  
  1065.    short i;
  1066.  
  1067.    /* Close all the open pipes! */
  1068.    for(i=0; i<MAXPIPES; i++)
  1069.    {
  1070.        if(poarray[i].fptr)
  1071.        {
  1072.            pclose(poarray[i].fptr);
  1073.        } /* if */
  1074.    } /* for */
  1075.  
  1076.  /* _STD_4000_popen */
  1077.  
  1078. ifdef NOTDEF
  1079.  
  1080. har *mktemp(char * template)
  1081.  
  1082.    register char *cp;
  1083.    register unsigned long val;
  1084.  
  1085.    cp = template;
  1086.    cp += strlen(cp);
  1087.    for (val = (unsigned long) FindTask(0L) ; ; )
  1088.        if (*--cp == 'X') {
  1089.            *cp = val%10 + '0';
  1090.            val /= 10;
  1091.        } else if (*cp != '.')
  1092.            break;
  1093.  
  1094.    if (*++cp != 0) {
  1095.        *cp = 'A';
  1096.        while (access(template, 0) == 0) {
  1097.            if (*cp == 'Z') {
  1098.                *template = 0;
  1099.                break;
  1100.            }
  1101.            ++*cp;
  1102.        }
  1103.    } else {
  1104.        if (access(template, 0) == 0)
  1105.            *template = 0;
  1106.    }
  1107.    return template;
  1108.  
  1109.  
  1110. endif
  1111.  
  1112. * WATCH OUT! This only works without __saveds because of the special
  1113.   SAS/C 6.1 tricks I use! Check the output with omd! */
  1114. tatic int __interrupt childprocess(void)
  1115.  
  1116.    struct ExecBase *SysBase = *((struct ExecBase **)4);
  1117.    struct Library *DOSBase;
  1118.    struct Process  *me;
  1119.    struct POmsg    *startupmsg;
  1120.    int             i = RETURN_FAIL;
  1121.  
  1122.    /* find our process structure */
  1123.    me = (struct Process *) FindTask(NULL);
  1124.  
  1125.    /* Wait for the parent to kick us off */
  1126.    WaitPort(&me->pr_MsgPort);
  1127.  
  1128.    /* Get the command to execute */
  1129.    startupmsg = (struct POmsg *) GetMsg(&me->pr_MsgPort);
  1130.  
  1131.    DOSBase = startupmsg->DOSBase;
  1132.  
  1133.    if(DOSBase)
  1134.    {
  1135.        /* Now run the command.  stdin and stdout are already set up */
  1136.        i = SystemTags(startupmsg->cmd,
  1137.               SYS_UserShell, 1,
  1138.               TAG_DONE);
  1139.    } /* if */
  1140.  
  1141.    if(i > 0)
  1142.    {
  1143.        /* UNIX compatibility ... */
  1144.        i <<= 8;
  1145.    } /* if */
  1146.  
  1147.    startupmsg->rc = i;
  1148.    /* pass the exit code back to the parent */
  1149.    ReplyMsg((struct Message *) startupmsg);
  1150.    return(0);
  1151.  
  1152. net.lib/PrintNetFault                                   net.lib/PrintNetFault
  1153.  
  1154.    NAME
  1155.        PrintNetFault - socket error messages
  1156.  
  1157.    SYNOPSIS
  1158.        PrintNetFault(code, banner)
  1159.        void PrintNetFault(LONG, const UBYTE *)
  1160.  
  1161.    FUNCTION
  1162.        The PrintNetFault() function finds the error message corresponding
  1163.        to the code and writes it, followed by a newline, to the standard
  1164.        error or Output() filehandle. If the argument string is non-NULL it
  1165.        is preappended to the message string and separated from it by a
  1166.        colon and space (`: '). If string is NULL only the error message
  1167.        string is printed.
  1168.  
  1169.    NOTES
  1170.        The PrintNetFault() function uses the DOS IO functions.
  1171.  
  1172.    SEE ALSO
  1173.        strerror(), perror(), <netinclude:sys/errno.h>
  1174.  
  1175. net.lib/PrintUserFault                                 net.lib/PrintUserFault
  1176.  
  1177.    NAME
  1178.        PrintUserFault - socket error messages
  1179.  
  1180.    SYNOPSIS
  1181.        PrintUserFault(code, banner)
  1182.        void PrintUserFault(LONG, const UBYTE *)
  1183.  
  1184.    FUNCTION
  1185.        The PrintUserFault() function finds the error message corresponding to
  1186.        the code and writes it, followed by a newline, to the standard error
  1187.        or Output() filehandle. If the argument string is non-NULL it is
  1188.        preappended to the message string and separated from it by a colon and
  1189.        space (`: '). If string is NULL only the error message string is
  1190.        printed.
  1191.  
  1192.    NOTES
  1193.        The PrintUserFault() function used the DOS io functions.  It is
  1194.        recommended to use PrintUserFault() when the standard C IO functions
  1195.        are not otherwise in use.
  1196.  
  1197.    SEE ALSO
  1198.        strerror(), perror(), <netinclude:sys/errno.h>
  1199.  
  1200. net.lib/rcmd                                                     net.lib/rcmd
  1201.  
  1202.    NAME
  1203.        rcmd, rresvport - routines for returning a stream to a remote command
  1204.  
  1205.    SYNOPSIS
  1206.        #include <clib/socket_protos.h>
  1207.  
  1208.        int rcmd(char **ahost, int inport, const char *locuser, 
  1209.                 const char *remuser, const char *cmd, int *fd2p);
  1210.  
  1211.        int rresvport(int *port);
  1212.  
  1213.    FUNCTION
  1214.        The rcmd() function is used by the super-user to execute a command on
  1215.        a remote machine using an authentication scheme based on reserved port
  1216.        numbers.  The rresvport() function returns a descriptor to a socket
  1217.        with an address in the privileged port space.  Both functions are
  1218.        present in the same file and are used by the rsh command (among
  1219.        others).
  1220.  
  1221.        The rcmd() function looks up the host *ahost using gethostbyname(),
  1222.        returning -1 if the host does not exist.  Otherwise *ahost is set to
  1223.        the standard name of the host and a connection is established to a
  1224.        server residing at the well-known Internet port inport.
  1225.  
  1226.        If the connection succeeds, a socket in the Internet domain of type
  1227.        SOCK_STREAM is returned to the caller, and given to the remote command
  1228.        as stdin and stdout. If fd2p is non-zero, then an auxiliary channel to
  1229.        a control process will be set up, and a descriptor for it will be
  1230.        placed in *fd2p. The control process will return diagnostic output
  1231.        from the command (unit 2) on this channel, and will also accept bytes
  1232.        on this channel as being UNIX signal numbers, to be forwarded to the
  1233.        process group of the command.  If fd2p is 0, then the stderr (unit 2
  1234.        of the remote command) will be made the same as the stdout and no
  1235.        provision is made for sending arbitrary signals to the remote process,
  1236.        although you may be able to get its attention by using out-of-band
  1237.        data.
  1238.  
  1239.        The protocol is described in detail in netutil/rshd.
  1240.  
  1241.        The rresvport() function is used to obtain a socket with a privileged
  1242.        address bound to it.  This socket is suitable for use by rcmd() and
  1243.        several other functions.  Privileged Internet ports are those in the
  1244.        range 0 to 1023.  Only the super-user is allowed to bind an address of
  1245.        this sort to a socket.
  1246.  
  1247.    DIAGNOSTICS
  1248.        The rcmd() function returns a valid socket descriptor on success.  It
  1249.        returns -1 on error and prints a diagnostic message on the standard
  1250.        error.
  1251.  
  1252.        The rresvport() function returns a valid, bound socket descriptor on
  1253.        success.  It returns -1 on error with the global value errno set
  1254.        according to the reason for failure.  The error code EAGAIN is
  1255.        overloaded to mean `All network ports in use.'
  1256.  
  1257.    SEE ALSO
  1258.        netutil/rlogin,  netutil/rsh,  rexec(),  netutil/rexecd,
  1259.        netutil/rlogind, netutil/rshd
  1260.  
  1261. net.lib/serveraccept                                     net.lib/serveraccept
  1262.  
  1263.    NAME
  1264.        serveraccept - Accept a server connection on named port
  1265.  
  1266.    SYNOPSIS
  1267.        socket = serveraccept(name, peer);
  1268.  
  1269.        long serveraccept(char *, struct sockaddr_in *);
  1270.  
  1271.    DESCRIPTION
  1272.        The serveraccept() library call binds a socket to the named Internet
  1273.        TCP port. Then it listens the socket and accepts the connection to
  1274.        the port. The peer's socket address is returned in sockaddr pointed
  1275.        by sockaddr argument.
  1276.  
  1277.        The port name is resolved by getservbyname() call. A numeric value
  1278.        for port name is also accepted.
  1279.  
  1280.        This module is meant for daemon developing.
  1281.  
  1282.    INPUTS
  1283.        name   - port name or numeric string.
  1284.        peer   - pointer to struct sockaddr_in
  1285.  
  1286.    RESULT
  1287.        socket - positive socket id for success or -1 for failure.
  1288.  
  1289.        peer   - sockaddr_in structure containing peer's internet address.
  1290.                 Note that on error, the structure containing peer address
  1291.                 is not necessarily updated.
  1292.  
  1293.    SEE ALSO
  1294.        bsdsocket/accept, bsdsocket/getservbyname
  1295.  
  1296. net.lib/set_socket_stdio                             net.lib/set_socket_stdio
  1297.  
  1298.    NAME
  1299.        set_socket_stdio - redirect stdio to/from a socket
  1300.  
  1301.    SYNOPSIS
  1302.        int set_socket_stdio(int sock);
  1303.  
  1304.    FUNCTION
  1305.        Redirect stdio (stdin, stdout and stderr) to/from socket 'sock'.
  1306.        This is done by dup2()'ing 'sock' to the level 1 files underneath
  1307.        the stdin, stdout and stderr.
  1308.  
  1309.        The original 'sock' reference is closed on successful return, so
  1310.        the socket descriptor given as argument should not be used after
  1311.        this function returns (successfully).
  1312.  
  1313.    RETURN VALUES
  1314.        0 if successful, -1 on error. Global variable 'errno' contains
  1315.        the specific error code set by the failing function.
  1316.  
  1317.    NOTES
  1318.        This module pulls in the link library stdio modules.
  1319.  
  1320.    SEE ALSO
  1321.        dup2()
  1322. net.lib/sleep                                                   net.lib/sleep
  1323.  
  1324.    NAME
  1325.        sleep - suspend process execution for the specified time
  1326.  
  1327.    SYNOPSIS
  1328.        void sleep(unsigned int seconds);
  1329.  
  1330.    FUNCTION
  1331.        Process execution is suspended for number of seconds specified in 
  1332.        'seconds'. The sleep will be aborted if any of the break signals
  1333.        specified for the process is received (only CTRL-C by default).
  1334.  
  1335.    PORTABILITY
  1336.        UNIX
  1337.  
  1338.    INPUTS
  1339.        'seconds' - number of seconds to sleep.
  1340.  
  1341.    RESULT
  1342.        Does not return a value.
  1343.  
  1344.    NOTES
  1345.        The sleep is implemented as a single select() call with all other
  1346.        than time out argument as NULL.
  1347.  
  1348.    SEE ALSO
  1349.        bsdsocket.library/select()
  1350.  
  1351. net.lib/SPrintf                                               net.lib/SPrintf
  1352.  
  1353.    NAME        
  1354.        SPrintf -- formatted print to a buffer
  1355.  
  1356.    SYNOPSIS
  1357.        len = SPrintf(Buffer, FormatString, Arguments...)
  1358.        len = VSPrintf(Buffer, FormatString, ap)
  1359.  
  1360.        ULONG SPrintf(STRPTR, const char *, ...)
  1361.        ULONG VSPrintf(STRPTR, const char *,  va_list)
  1362.  
  1363.    FUNCTION
  1364.        Prints to a simple buffer or to a CSource buffer. These functions
  1365.        are similar to C-library sprintf() with RawDoFmt() formatting.
  1366.  
  1367.    INPUTS
  1368.        Buffer - Pointer to buffer.
  1369.        FormatString - This is a printf()-style format string as defined
  1370.            in exec.library/RawDoFmt().
  1371.        Arguments - as in printf() .
  1372.  
  1373.        Result - Pointer to CSource structure.
  1374.  
  1375.    RESULT
  1376.        Number of characters printed.
  1377.  
  1378.    EXAMPLE
  1379.        SPrintf(mybuf, "line=%ld, val=%lx\n", 
  1380.                __LINE__, very.interesting->value);
  1381.  
  1382.    BUGS
  1383.        Function SPrintf() assumes that no print is longer than 1024 chars.
  1384.        It does not check for buffer owerflow (there no way to check, the
  1385.        definition of sprintf misses it).
  1386.  
  1387.        SPrintf strings are truncated to maximum of 1024 chars (including
  1388.        final NUL)
  1389.  
  1390.    SEE ALSO
  1391.        exec.library/RawDoFmt()
  1392.  
  1393. net.lib/stat                                                     net.lib/stat
  1394.  
  1395.    NAME
  1396.        stat, lstat, fstat - get file status
  1397.  
  1398.    SYNOPSIS
  1399.        #include <sys/types.h>
  1400.        #include <sys/stat.h>
  1401.  
  1402.        success = stat(path, buf)
  1403.  
  1404.        int stat(const char *, struct stat *);
  1405.  
  1406.        success =  lstat(path, buf);
  1407.  
  1408.        int lstat(const char *, struct stat *);
  1409.  
  1410.        success = fstat(fd, buf);
  1411.  
  1412.        int fstat(int, struct stat *);
  1413.  
  1414.    DESCRIPTION
  1415.        The stat() function obtains information about the file pointed to by
  1416.        path. Read, write or execute permission of the named file is not
  1417.        required, but all directories listed in the path name leading to the
  1418.        file must be seachable.
  1419.  
  1420.        Lstat() is like stat() except in the case where the named file is a
  1421.        symbolic link, in which case lstat() returns information about the
  1422.        link, while stat() returns information about the file the link
  1423.        references.
  1424.  
  1425.        The fstat() obtains the same information about an open file known by
  1426.        the file descriptor fd, such as would be obtained by an open call.
  1427.  
  1428.        Buf is a pointer to a stat() structure as defined by <sys/stat.h>
  1429.        (shown below) and into which information is placed concerning the
  1430.        file.
  1431.  
  1432.           struct  stat
  1433.           {
  1434.             dev_t   st_dev;         /* unique device id */ 
  1435.             ino_t   st_ino;         /* inode of file (key block) */ 
  1436.             mode_t  st_mode;        /* Unix style mode */ 
  1437.             ushort  st_nlink;       /* number of links (unimplemented) */ 
  1438.             uid_t   st_uid;         /* owner's user ID */ 
  1439.             gid_t   st_gid;         /* owner's group ID */ 
  1440.             dev_t   st_rdev;        /* special file ID (unimplemented) */ 
  1441.             off_t   st_size;        /* file size */ 
  1442.             time_t  st_atime;       /* Time of last access */ 
  1443.             time_t  st_mtime;       /* Last modification time */ 
  1444.             time_t  st_ctime;       /* Last file status change time */ 
  1445.             long    st_blksize;     /* Size of disk block */ 
  1446.             long    st_blocks;      /* Size in blocks */ 
  1447.             long    st_dosmode;     /* DOS protection bits */ 
  1448.             short   st_type;        /* DOS file type */ 
  1449.             char   *st_comment;     /* DOS file comment */ 
  1450.           };
  1451.  
  1452.        The time-related fields of struct stat have same contents, time when
  1453.        file data last modified.
  1454.  
  1455.        The status information word st_mode has bits as follows:
  1456.  
  1457.          #define S_ISUID  0004000    /* set user id on execution */ 
  1458.          #define S_ISGID  0002000    /* set group id on execution */ 
  1459.          #define S_ISVTX  0001000    /* save swapped text even after use */ 
  1460.          #define S_IRUSR  0000400    /* read permission for owner */ 
  1461.          #define S_IWUSR  0000200    /* write permission for owner */ 
  1462.          #define S_IXUSR  0000100    /* execute permission for owner */ 
  1463.          #define S_IRGRP  0000040    /* read permission for group */ 
  1464.          #define S_IWGRP  0000020    /* write permission for group */ 
  1465.          #define S_IXGRP  0000010    /* execute permission for group */ 
  1466.          #define S_IROTH  0000004    /* read permission for other */ 
  1467.          #define S_IWOTH  0000002    /* write permission for other */ 
  1468.          #define S_IXOTH  0000001    /* execute permission for other */ 
  1469.          #define S_IFCHR  0020000    /* character special */ 
  1470.          #define S_IFDIR  0040000    /* directory */ 
  1471.          #define S_IFBLK  0060000    /* block special */ 
  1472.          #define S_IFREG  0100000    /* regular */ 
  1473.          #define S_IFLNK  0120000    /* symbolic link */ 
  1474.          #define S_IFSOCK 0140000    /* socket */ 
  1475.          #define S_IFIFO  0010000    /* named pipe (fifo) */ 
  1476.  
  1477.        For a list of access modes, see <sys/stat.h>, access(2) and chmod(2).
  1478.  
  1479.    RETURN VALUES
  1480.        Upon successful completion a value of 0 is returned.  Otherwise, a
  1481.        value of -1 is returned and errno is set to indicate the error.
  1482.  
  1483.    ERRORS
  1484.        The functions stat() and lstat() will fail if:
  1485.  
  1486.        [ENOTDIR]       A component of the path prefix is not a directory.
  1487.  
  1488.        [ENAMETOOLONG]  A component of a pathname exceeded 255 characters,
  1489.                        or an entire path name exceeded 1023 characters.
  1490.  
  1491.        [ENOENT]        The named file does not exist.
  1492.  
  1493.        [ELOOP]         Too many symbolic links were encountered in
  1494.                        translating the pathname.
  1495.  
  1496.        [EACCES]        Search permission is denied for a component of the
  1497.                        path prefix.
  1498.  
  1499.        [EFAULT]        Buf or name points to an invalid address.
  1500.  
  1501.        [EIO]           An I/O error occurred while reading from or writing
  1502.                        to the file system.
  1503.  
  1504.        The function fstat() will fail if:
  1505.  
  1506.        [EBADF]   fd is not a valid open file descriptor.
  1507.  
  1508.        [EFAULT]  Buf points to an invalid address.
  1509.  
  1510.        [EIO]     An I/O error occurred while reading from or writing to the
  1511.                  file system.
  1512.  
  1513.    SEE ALSO
  1514.        chmod(),  chown()
  1515.  
  1516.    BUGS 
  1517.        Applying fstat to a socket returns a zero'd buffer.
  1518.  
  1519. net.lib/strerror                                             net.lib/strerror
  1520.  
  1521.    NAME
  1522.        strerror -- return the text for given error number
  1523.  
  1524.    SYNOPSIS
  1525.        string = strerror(error);
  1526.  
  1527.        char * strerror(int);
  1528.  
  1529.    FUNCTION
  1530.        This function returns pointer to the (English) string describing the
  1531.        error code given as argument. The error strings are defined for the
  1532.        error codes defined in <sys/errno.h>.
  1533.  
  1534.    NOTES
  1535.        The string pointed to by the return value should not be modified by
  1536.        the program, but may be overwritten by a subsequent call to this
  1537.        function.
  1538.  
  1539.    BUGS
  1540.        The strerror() prototype should be 
  1541.        const char *strerror(unsigned int); 
  1542.        However, the SAS C includes define it differently.
  1543.  
  1544.    SEE ALSO
  1545.        <netinclude:sys/errno.h>, perror(), PrintNetFault()
  1546. net.lib/syslog                                                 net.lib/syslog
  1547.  
  1548.    NAME   
  1549.        openlog(), closelog(), setlogmask() -- syslog utility functions
  1550.  
  1551.    SYNOPSIS
  1552.        #include <syslog.h>
  1553.        
  1554.        openlog(ident, logopt, facility);
  1555.  
  1556.        void openlog(const char *, int, int);
  1557.  
  1558.        closelog();
  1559.  
  1560.        void closelog(void);
  1561.  
  1562.        oldmask = setlogmask(maskpri);
  1563.        
  1564.        int setlogmask(int);
  1565.        
  1566.    FUNCTION
  1567.        openlog() can be called to initialize the log file, if special
  1568.        processing is needed.  ident is a string that precedes every
  1569.        message.  logopt is a mask of bits, logically OR'ed together,
  1570.        indicating logging options.  The values for logopt are:
  1571.        
  1572.             LOG_PID             Log the process ID with each message;
  1573.                                 useful for identifying instantiations
  1574.                                 of daemons.
  1575.  
  1576.             LOG_CONS            Force writing messages to the console
  1577.                                 if unable to send it to syslogd.
  1578.                                 This option is safe to use in daemon
  1579.                                 processes that have no controlling
  1580.                                 terminal because syslog() forks
  1581.                                 before opening the console.
  1582.  
  1583.             LOG_NDELAY          Open the connection to syslogd
  1584.                                 immediately.  Normally, the open is
  1585.                                 delayed until the first message is
  1586.                                 logged.  This is useful for programs
  1587.                                 that need to manage the order in
  1588.                                 which file descriptors are allocated.
  1589.  
  1590.             LOG_NOWAIT          Do not wait for children forked to
  1591.                                 log messages on the console. Obsolete
  1592.                                 in AmiTCP/IP, since AmiTCP/IP does
  1593.                                 not fork.
  1594.  
  1595.        facility encodes a default facility to be assigned to all
  1596.        messages written subsequently by syslog() with no explicit
  1597.        facility encoded. The facility codes are:
  1598.  
  1599.             LOG_KERN            Messages generated by the kernel.
  1600.                                 These cannot be generated by any user
  1601.                                 processes.
  1602.  
  1603.             LOG_USER            Messages generated by random user
  1604.                                 processes.  This is the default
  1605.                                 facility identifier if none is
  1606.                                 specified.
  1607.  
  1608.             LOG_MAIL            The mail system.
  1609.  
  1610.             LOG_DAEMON          System daemons, such as inetd, ftpd,
  1611.                                 etc.
  1612.  
  1613.             LOG_AUTH            The authorization system: login, su,
  1614.                                 getty, etc.
  1615.  
  1616.             LOG_LPR             The line printer spooling system: lp,
  1617.                                 lpsched, etc.
  1618.  
  1619.             LOG_LOCAL0          Reserved for local use. Similarly for
  1620.                                 LOG_LOCAL1 through LOG_LOCAL7.
  1621.  
  1622.  
  1623.        closelog() closes the log file.
  1624.  
  1625.        setlogmask() sets the log priority mask to maskpri and returns
  1626.        the previous mask.  Calls to syslog() with a priority not set
  1627.        in maskpri are rejected.  The mask for an individual priority
  1628.        pri is calculated by the macro LOG_MASK(pri); the mask for all
  1629.        priorities up to and including toppri is given by the macro
  1630.        LOG_UPTO(toppri).  By default, all priorities are logged.
  1631.  
  1632.    EXAMPLES
  1633.        who logs a message regarding some sort of unexpected and
  1634.        serious error:
  1635.  
  1636.            syslog(LOG_ALERT, "who: internal error 23");
  1637.  
  1638.        ftpd uses openlog() to arrange to log its process ID, to log
  1639.        to the console if necessary, and to log in the name of the
  1640.        daemon facility:
  1641.  
  1642.            openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
  1643.  
  1644.        Arrange to log messages only at levels LOG_ERR and lower:
  1645.  
  1646.            setlogmask(LOG_UPTO(LOG_ERR));
  1647.  
  1648.        Typical usage of syslog() to log a connection:
  1649.  
  1650.            syslog(LOG_INFO, "Connection from host %d", CallingHost);
  1651.  
  1652.        If the facility has not been set with openlog(), it defaults
  1653.        to LOG_USER.
  1654.  
  1655.        Explicitly set the facility for this message:
  1656.  
  1657.            syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
  1658.        
  1659.    NOTES
  1660.        openlog() does not copy and store the ident string internally;
  1661.        it stores only the character pointer.  Therefore it is the
  1662.        responsibility of the programmer to make sure that the ident
  1663.        argument points to the correct string while syslog() is being
  1664.        called. 
  1665.  
  1666.    BUGS
  1667.        Most of the logopt and facility codes are currently being
  1668.        ignored by AmiTCP/IP, but they should be used for future
  1669.        compatibility.
  1670.  
  1671.        The autoinit module of the net.lib tells the program name 
  1672.        to the AmiTCP/IP at program startup, so use of the openlog()
  1673.        for that purpose only is not necessary.
  1674.  
  1675.    AUTHOR
  1676.        syslog() was developed by the University of California,
  1677.        Berkeley.
  1678.  
  1679.    SEE ALSO
  1680.        bsdsocket.library/syslog(), bsdsocket.library/SocketBaseTagList()
  1681. net.lib/usleep                                                 net.lib/usleep
  1682.  
  1683.    NAME
  1684.        usleep - suspend process execution for the specified time
  1685.  
  1686.    SYNOPSIS
  1687.        void usleep(unsigned int microseconds);
  1688.  
  1689.    FUNCTION
  1690.        Process execution is suspended for number of microseconds
  1691.        specified in 'microseconds'. The sleep will be aborted if any
  1692.        of the break signals specified for the process is received
  1693.        (only CTRL-C by default).
  1694.  
  1695.    PORTABILITY
  1696.        UNIX
  1697.  
  1698.    INPUTS
  1699.        'microseconds' - number of microseconds to sleep.
  1700.  
  1701.    RESULT
  1702.        Does not return a value.
  1703.  
  1704.    NOTES
  1705.        The sleep is implemented as a single select() call with all other
  1706.        than time out argument as NULL.
  1707.  
  1708.    SEE ALSO
  1709.        bsdsocket.library/select()
  1710.  
  1711. net.lib/utime                                                   net.lib/utime
  1712.  
  1713.    NAME
  1714.        utime - set file access and modification times
  1715.  
  1716.    SYNOPSIS
  1717.        #include <utime.h>
  1718.  
  1719.        int error = utime(const char *name, const struct utimbuf *times)
  1720.  
  1721.    FUNCTION
  1722.        The access and modification times for the file 'name' are modified
  1723.        according to the 'times'. If 'times' is NULL, the times are set to
  1724.        systems current time.
  1725.  
  1726.    PORTABILITY
  1727.        UNIX
  1728.  
  1729.    INPUTS
  1730.        'name'  - the name of the file to be affected.
  1731.  
  1732.        'times' - pointer to a structure containing the time values,
  1733.                  defined in <utime.h> as:
  1734.  
  1735.                      struct utimbuf {
  1736.                          time_t actime;        /* Access time */
  1737.                          time_t modtime;        /* Modification time */
  1738.                      };
  1739.  
  1740.                  Both times are in units of seconds since Jan. 1, 1970,
  1741.                  Greenwich Mean Time.
  1742.  
  1743.                  If the 'times' is given as the NULL pointer, the current
  1744.                  time is used.
  1745.  
  1746.    RESULT
  1747.        Returns 0 when successful and -1 with specific error code in errno in
  1748.        case of an error.
  1749.  
  1750.    NOTES
  1751.        Since AmigaDOS files have only one time stamp, both access and
  1752.        modification times cannot be supported. Since the AmigaDOS file date
  1753.        is the modification time, only the 'modtime' field of the 'times' is
  1754.        used.
  1755.  
  1756.        The conversion from 1.1.1970 based GMT to 1.1.1978 based local time is
  1757.        done with external long __local_to_GMT, which is defined and
  1758.        initialized by the timerinit.c module included in the net.lib.
  1759.  
  1760.    SEE ALSO
  1761.        dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
  1762.  
  1763. netd.lib/dosio_init                                       netd.lib/dosio_init
  1764.  
  1765.    NAME
  1766.        dosio_init - (std) io macros to dos.library V37 or newer
  1767.  
  1768.    SYNOPSIS
  1769.        long _STI_500_dosio_init(void)
  1770.  
  1771.    FUNCTION
  1772.        This function initializes the file table used by the stdio
  1773.        look-a-like macros defined in <netinclude:stdio.h>.
  1774.  
  1775.        These macros are taken in to use by defining the symbol
  1776.        `USE_DOSIO' before including any include files.  When this is
  1777.        done, the normal stdio prototypes are replaced with macros,
  1778.        which call the corresponding dos.library functions.  The
  1779.        netd.lib provides the initialization function mentioned above
  1780.        and the functions VSPrintf(), SPrintf(), VCSPrintf() and
  1781.        CSPrintf(), which are not found from the dos.library.
  1782.  
  1783.        The stdio macros provided are suitable for stdin, stdout and
  1784.        stderr usage. No file opening function (fopen()) is provided,
  1785.        so the use is quite limited.
  1786.  
  1787.        The netd.lib version of the net.lib is compiled with this
  1788.        USE_DOSIO, so you will want to use that instead of the
  1789.        net.lib to make your executable smaller if your own program
  1790.        does not use stdio of the C runtime library.
  1791.  
  1792.    NOTES
  1793.        The stdio macros rely on dos.library 37 or newer being present.
  1794.  
  1795.        The autoinitialization and autotermination functions are features
  1796.        specific to the SAS C6.  However, these functions can be used with
  1797.        other (ANSI) C compilers, too. Example follows:
  1798.  
  1799.        /* at start of main() */
  1800.  
  1801.        if (_STI_500_dosio_init() != 0)
  1802.           exit(20);
  1803.  
  1804.    BUGS
  1805.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  1806.        6.50 or latter.  Only way to terminate an initialization function is
  1807.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  1808.        function is terminated by exit() call with SAS C 6.50 binary, the
  1809.        autotermination functions won't be called.  Due this braindamage
  1810.        the libraries must be separately compiled for each compiler version.
  1811.  
  1812.    SEE ALSO
  1813.  
  1814.  
  1815.